	function add_new_branhcode(){
		var branhcode = document.getElementById('BRNCODE').value;	
		var branhlist = document.getElementById('LIST_BRANHCODE').value;
		var branh_arr = branhlist.split('|');
		var stringbranh='';
		var num=0;
		if(branhcode=='ALL'){
			document.getElementById('LIST_BRANHCODE').value='';
			document.getElementById('LIST_BRANHCODE').value='ALL';
			num=1;
		}
		//alert(branhlist.replace('|',''));
		if(branhlist.replace('|','')=='ALL'){
			num=1;	
		}
		for(i in branh_arr){
			if (branh_arr[i]==branhcode){
				num=1;
				break;
			}
		}
		if(num==0){
			stringbranh = branhcode;
			document.getElementById('LIST_BRANHCODE').value = document.getElementById('LIST_BRANHCODE').value + stringbranh +"|";
		}
	}
	
	function delete_branh(){
		var i;
		var num=0;
		var branhcode = document.getElementById('BRNCODE').value;
		var branhlist = document.getElementById('LIST_BRANHCODE').value;
		var branh_arr = branhlist.split('|');
		if(branhlist.replace('|','')==branhcode){
			document.getElementById('LIST_BRANHCODE').value='';
			num=1;
		}
		if(num==0){
			for(i in branh_arr){
				if(branh_arr[i]==branhcode){	
					branhlist = branhlist.replace(branhcode+'|','');
				}
			}
			document.getElementById('LIST_BRANHCODE').value = branhlist;
		}
	}
	
	function add_new_acct(){
		var acct = document.getElementById('ACTNO').value;	
		var acctlist = document.getElementById('LIST_ACCOUNT').value;
		var acct_arr = acctlist.split('|');
		var stringacct='';
		var num=0;
		for(i in acct_arr){
			if (acct_arr[i]==acct){
				num=1;
				break;
			}
		}
		if(num==0){
			stringacct = acct;
			document.getElementById('LIST_ACCOUNT').value = document.getElementById('LIST_ACCOUNT').value + stringacct +"|";
		}
	}
	
	function delete_acct(){
		var i;
		var num=0;
		var acct = document.getElementById('ACTNO').value;
		var acctlist = document.getElementById('LIST_ACCOUNT').value;
		var acct_arr = acctlist.split('|');
		if(acctlist.replace('|','')==acct){
			document.getElementById('LIST_ACCOUNT').value='';
			num=1;
		}
		if(num==0){
			for(i in acct_arr){
				if(acct_arr[i]==acct){	
					acctlist = acctlist.replace(acct+'|','');
				}
			}
			document.getElementById('LIST_ACCOUNT').value = acctlist;
		}
	}
	
	function add_new_noco(){
		var noco = document.getElementById('NOCO').value;	
		var nocolist = document.getElementById('LIST_NOCO').value;
		var noco_arr = nocolist.split('|');
		var stringnoco='';
		var num=0;
		if(noco=='ALL'){
			document.getElementById('LIST_NOCO').value='';
			document.getElementById('LIST_NOCO').value='ALL';
			num=1;
		}
		//alert(nocolist.replace('|',''));
		if(nocolist.replace('|','')=='ALL'){
			num=1;
		}
		for(i in noco_arr){
			if (noco_arr[i]==noco){
				num=1;
				break;
			}
		}
		if(num==0){
			stringnoco = noco;
			document.getElementById('LIST_NOCO').value = document.getElementById('LIST_NOCO').value + stringnoco +"|";
		}
	}
	
	function delete_noco(){
		//alert(1);
		var i;
		var num=0;
		var noco = document.getElementById('NOCO').value;
		var nocolist = document.getElementById('LIST_NOCO').value;
		var noco_arr = nocolist.split('|');
		if(nocolist.replace('|','')==noco){
			document.getElementById('LIST_NOCO').value='';
			num=1;
		}
		if(num==0){
			for(i in noco_arr){
				//alert(noco);
				if(noco_arr[i]==noco){	
					nocolist = nocolist.replace(noco+'|','');
				}
			}
			document.getElementById('LIST_NOCO').value = nocolist;
		}
	}
	
	function add_new_loaitien(){
		var loaitien = document.getElementById('LOAITIEN').value;	
		var loaitienlist = document.getElementById('LIST_LOAITIEN').value;
		var loaitien_arr = loaitienlist.split('|');
		var stringloaitien='';
		var num=0;
		if(loaitien=='ALL'){
			document.getElementById('LIST_LOAITIEN').value='';
			document.getElementById('LIST_LOAITIEN').value='ALL';
			num=1;
		}
		//alert(loaitienlist.replace('|',''));
		if(loaitienlist.replace('|','')=='ALL'){
			num=1;
		}
		for(i in loaitien_arr){
			if (loaitien_arr[i]==loaitien){
				num=1;
				break;
			}
		}
		if(num==0){
			stringloaitien = loaitien;
			document.getElementById('LIST_LOAITIEN').value = document.getElementById('LIST_LOAITIEN').value + stringloaitien +"|";
		}
	}
	
	function delete_loaitien(){
		//alert(1);
		var i;
		var num=0;
		var loaitien = document.getElementById('LOAITIEN').value;
		var loaitienlist = document.getElementById('LIST_LOAITIEN').value;
		var loaitien_arr = loaitienlist.split('|');
		if(loaitienlist.replace('|','')==loaitien){
			document.getElementById('LIST_LOAITIEN').value='';
			num=1;
		}
		if(num==0){
			for(i in loaitien_arr){
				if(loaitien_arr[i]==loaitien){	
					loaitienlist = loaitienlist.replace(loaitien+'|','');
				}
			}
			document.getElementById('LIST_LOAITIEN').value = loaitienlist;
		}
	}
	
	function valbutton_acct(thisform,objname) {
		var objradio = thisform.radioTK;
		var radioLength = objradio.length;
		var id, i, curr, dc;
		if(!radioLength){
			id = objradio.value;		
		}else{
			for(i = 0; i < radioLength; i++){
				if(thisform.radioTK[i].checked){
					curr = document.getElementById('LOAITIEN'+i).value
					dc = document.getElementById('DC_LIST'+i).value
					id = thisform.radioTK[i].value +'#'+ dc +'#'+ curr;
					break;
				}
			}
		}
		var name = id;	
		var lblname = objname;
		//alert(objname);
		//alert(name);
		var obj = window.opener.document.getElementById(lblname);
		
		if(obj){
			obj.value = name;
		}
		
		window.close();
	}
	
	function valbutton_branh(thisform,objname) {
		var objradio = thisform.radioTK;
		var radioLength = objradio.length;
		var id, i;
		if(!radioLength){
			id = objradio.value;		
		}else{
			for(i = 0; i < radioLength; i++){
				if(thisform.radioTK[i].checked){
					id = thisform.radioTK[i].value;
					break;
				}
			}
		}
		var name = id.split('-');	
		//alert(objname);
		var lblname = objname.split('-');
		var obj1 = window.opener.document.getElementById(lblname[0]);
		var obj2 = window.opener.document.getElementById(lblname[1]);
		if(obj1){
			obj1.value = name[0];
			var phongtructhuoc = window.opener.document.getElementById("phongtructhuoc");
			if(phongtructhuoc){
				phongtructhuoc.click();	
			}
		}
		if(obj2){
			obj2.value = name[1];
		}
		
		window.close();
	}
	
	function checkKey(evt){		
		evt = (evt) ? evt : ((window.event) ? event : null);
		if (evt) {
		   var elem = (evt.target) ? evt.target : 
			  ((evt.srcElement) ? evt.srcElement : null);
		   if (elem) {
			   var charCode = (evt.charCode) ? evt.charCode : 
				   ((evt.which) ? evt.which : evt.keyCode);
				
			   if (charCode == 13 ) {	
			   		//alert(charCode);		   		
					document.getElementById('replacement_find').click();	
					return false;					   
			   }else{
			   		return true;
			   }
		   }
		}
	}
	
	function number_branh(evt) {
		evt = (evt) ? evt : ((window.event) ? event : null);
		if (evt) {
		   var elem = (evt.target) ? evt.target : 
			  ((evt.srcElement) ? evt.srcElement : null);	   
		   if (elem) {
			   //var charCode = (evt.charCode) ? evt.charCode : 
				//   ((evt.which) ? evt.which : evt.keyCode);
			   var charCode = evt.which;
			   //alert(charCode);	   
			   if ((charCode < 32 ) || 
					charCode == 37 || charCode == 39 || charCode == 46 ||
				   (charCode > 44 && charCode < 47) || 
				   (charCode > 47 && charCode < 58)) {
				   return true;
			   } else {
				   return false;
			   }
		   }
		}		
	}
	
	
	function valbutton(thisform,objname) {
		var objradio = thisform.radioTK;
		var radioLength = objradio.length;
		var id, i;
		if(!radioLength){
			id = objradio.value;		
		}else{
			for(i = 0; i < radioLength; i++){
				if(thisform.radioTK[i].checked){
					id = thisform.radioTK[i].value;
					break;
				}
			}
		}
		var name = id.split('-');	
		//alert(objname);
		var lblname = objname.split('-');
		var obj1 = window.opener.document.getElementById(lblname[0]);
		var obj2 = window.opener.document.getElementById(lblname[1]);
		if(obj1){
			obj1.value = name[0];
		}
		if(obj2){
			obj2.value = name[1];
		}
		
		window.close();
	}